package com.baicun.wish.hadoop;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * @author baicun
 * @description 将Csv文件上传到HDFS
 */
public class UploadCsvToHDFS {
    public static void up(String csvName,String hdfsPath) throws IOException, URISyntaxException, InterruptedException {

        String csvPath = "Y:\\Projects\\IDEA\\development\\wish\\wish-data\\src\\main\\java\\com\\baicun\\wish\\csv\\"+csvName;

        FileSystem fileSystem = FileSystem.get(new URI("hdfs://master:9000"), new Configuration(),"root");

        //上传
        fileSystem.copyFromLocalFile(new Path(csvPath),new Path(hdfsPath));

        fileSystem.close();

    }
}
